﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CounterStrikeSourceAimbot
{
    public class WorldData : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged members and helpers

        public event PropertyChangedEventHandler PropertyChanged;

        private static bool AreEqualObjects(object obj1, object obj2)
        {
            var obj1Null = ReferenceEquals(obj1, null);
            var obj2Null = ReferenceEquals(obj2, null);

            if (obj1Null && obj2Null)
                return true;

            if (obj1Null || obj2Null)
                return false;

            if (obj1.GetType() != obj2.GetType())
                return false;

            if (ReferenceEquals(obj1, obj2))
                return true;

            return obj1.Equals(obj2);
        }

        private void OnPropertyChanged(params string[] propertyNames)
        {
            if (propertyNames == null)
                return;

            if (this.PropertyChanged != null)
                foreach (var propertyName in propertyNames)
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        #region MainPlayerPitch Property and field

        [Obfuscation(Exclude = true, ApplyToMembers = false)]
        public double MainPlayerPitch
        {
            get { return mainPlayerPitch; }
            set
            {
                if (AreEqualObjects(mainPlayerPitch, value))
                    return;

                var _fieldOldValue = mainPlayerPitch;

                mainPlayerPitch = value;

                WorldData.OnMainPlayerPitchChanged(this, new PropertyValueChangedEventArgs<double>(_fieldOldValue, value));

                this.OnPropertyChanged("MainPlayerPitch");
            }
        }

        private double mainPlayerPitch;

        public EventHandler<PropertyValueChangedEventArgs<double>> MainPlayerPitchChanged;

        public static void OnMainPlayerPitchChanged(object sender, PropertyValueChangedEventArgs<double> e)
        {
            var obj = sender as WorldData;

            if (obj.MainPlayerPitchChanged != null)
                obj.MainPlayerPitchChanged(obj, e);


        }

        #endregion

        #region MainPlayerLocation Property and field

        [Obfuscation(Exclude = true, ApplyToMembers = false)]
        public CSPoint MainPlayerLocation
        {
            get { return mainPlayerLocation; }
            set
            {
                if (AreEqualObjects(mainPlayerLocation, value))
                    return;

                var _fieldOldValue = mainPlayerLocation;

                mainPlayerLocation = value;

                WorldData.OnMainPlayerLocationChanged(this, new PropertyValueChangedEventArgs<CSPoint>(_fieldOldValue, value));

                this.OnPropertyChanged("MainPlayerLocation");
            }
        }

        private CSPoint mainPlayerLocation;

        public EventHandler<PropertyValueChangedEventArgs<CSPoint>> MainPlayerLocationChanged;

        public static void OnMainPlayerLocationChanged(object sender, PropertyValueChangedEventArgs<CSPoint> e)
        {
            var obj = sender as WorldData;

            if (obj.MainPlayerLocationChanged != null)
                obj.MainPlayerLocationChanged(obj, e);


        }

        #endregion
    }
}
